<template>
  <div class="add-admin">
    <div class="header">
      <h2>添加管理员</h2>
    </div>

    <div class="form-container">
      <form class="admin-form" @submit.prevent="handleSubmit">
        <!-- 基本信息 -->
        <div class="form-section">
          <h3>基本信息</h3>
          <div class="form-group">
            <label>用户名</label>
            <input type="text" v-model="form.username" required>
          </div>
          <div class="form-group">
            <label>姓名</label>
            <input type="text" v-model="form.name" required>
          </div>
          <div class="form-group">
            <label>密码</label>
            <input type="password" v-model="form.password" required>
          </div>
          <div class="form-group">
            <label>确认密码</label>
            <input type="password" v-model="form.confirmPassword" required>
          </div>
        </div>

        <!-- 角色信息 -->
        <div class="form-section">
          <h3>角色信息</h3>
          <div class="form-group">
            <label>管理员类型</label>
            <select v-model="form.role" required>
              <option value="school_admin">校级管理员</option>
              <option value="college_admin">院级管理员</option>
              <option value="class_admin">班级管理员</option>
            </select>
          </div>
          <div class="form-group" v-if="form.role !== 'school_admin'">
            <label>所属学院</label>
            <select v-model="form.collegeId" required>
              <option v-for="college in colleges" 
                      :key="college.id" 
                      :value="college.id">
                {{ college.name }}
              </option>
            </select>
          </div>
          <div class="form-group" v-if="form.role === 'class_admin'">
            <label>年级</label>
            <select v-model="form.grade" required>
              <option value="2021">2021级</option>
              <option value="2022">2022级</option>
              <option value="2023">2023级</option>
            </select>
          </div>
          <div class="form-group" v-if="form.role === 'class_admin'">
            <label>班级</label>
            <select v-model="form.classId" required>
              <option value="1">1班</option>
              <option value="2">2班</option>
              <option value="3">3班</option>
            </select>
          </div>
        </div>

        <!-- 权限设置 -->
        <div class="form-section">
          <h3>权限设置</h3>
          <div class="permissions">
            <div class="permission-item">
              <input type="checkbox" v-model="form.permissions.viewData">
              <label>查看数据</label>
            </div>
            <div class="permission-item">
              <input type="checkbox" v-model="form.permissions.editData">
              <label>编辑数据</label>
            </div>
            <div class="permission-item">
              <input type="checkbox" v-model="form.permissions.manageUsers">
              <label>用户管理</label>
            </div>
          </div>
        </div>

        <!-- 表单操作 -->
        <div class="form-actions">
          <button type="button" class="cancel-btn" @click="goBack">取消</button>
          <button type="submit" class="submit-btn">确认添加</button>
        </div>
      </form>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()

// 表单数据
const form = ref({
  username: '',
  name: '',
  password: '',
  confirmPassword: '',
  role: '',
  collegeId: '',
  grade: '',
  classId: '',
  permissions: {
    viewData: true,
    editData: false,
    manageUsers: false
  }
})

// 学院数据
const colleges = ref([
  { id: 1, name: '计算机科学与技术学院' },
  { id: 2, name: '工学院' },
  { id: 3, name: '理学院' }
])

// 提交表单
const handleSubmit = () => {
  // 处理表单提交逻辑
  console.log('提交表单:', form.value)
}

// 返回上一页
const goBack = () => {
  router.go(-1)
}
</script>

<style scoped>
.add-admin {
  padding: 24px;
  background: #f5f6fa;
  min-height: 100vh;
}

.header {
  margin-bottom: 24px;
}

.form-container {
  background: white;
  border-radius: 8px;
  padding: 24px;
  max-width: 800px;
  margin: 0 auto;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.form-section {
  margin-bottom: 32px;
  padding-bottom: 24px;
  border-bottom: 1px solid #f0f0f0;
}

.form-section h3 {
  margin-bottom: 16px;
  color: #333;
  font-size: 18px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  color: #666;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #d9d9d9;
  border-radius: 4px;
}

.permissions {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.permission-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 16px;
  padding-top: 24px;
}

.cancel-btn,
.submit-btn {
  padding: 8px 24px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
}

.cancel-btn {
  background: #f5f5f5;
  color: #666;
}

.submit-btn {
  background: #1890ff;
  color: white;
}

.submit-btn:hover {
  background: #40a9ff;
}
</style> 